package app.server.project.cloud.random.controller;

import app.server.project.cloud.random.dto.auth.WebLoginResp;
import app.server.project.core.constants.Def;
import app.server.project.core.http.RespModel;
import app.server.project.core.httpauth.UnAuth;
import app.server.project.cloud.random.dto.auth.AppLoginReq;
import app.server.project.cloud.random.dto.auth.AppLoginResp;
import app.server.project.cloud.random.dto.auth.WebLoginReq;
import app.server.project.cloud.random.service.AuthService;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.digest.MD5;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 权限模块
 */
@AllArgsConstructor
@RestController
@RequestMapping("/auth")
public class AuthController {

    private AuthService authService;

    /**
     * app 发送验证码
     * @param email
     */
    @PostMapping("/sendCode")
    @UnAuth
    public void sendCode(@RequestBody String email){
        this.authService.sendCode(email);
    }

    /**
     * app 登录
     * @param
     */
    @GetMapping("/appLogin")
    @UnAuth
    public RespModel<AppLoginResp> appLogin(@RequestBody AppLoginReq req){
        return RespModel.success(this.authService.appLogin(req));
    }

    /**
     * 硬件获取token
     * @param
     */
    @GetMapping("/devGetToken/{devId}")
    @UnAuth
    public RespModel<AppLoginResp> devGetToken(@PathVariable long devId){
        return RespModel.success(this.authService.devGetToken(devId));
    }

    /**
     * web获取token
     * @param
     */
    @PostMapping("/webGetToken")
    @UnAuth
    public RespModel<WebLoginResp> webGetToken(WebLoginReq req){
        return RespModel.success(this.authService.webGetToken(req));
    }

}
